﻿using HealthcareSystem.API.Write.Application.Command.EquipmentCommand;
using HealthcareSystem.Domain.BasicSettings.Equipment;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.EquipmentCommandHandler
{
    /// <summary>
    /// 修改设备请求命令
    /// </summary>
    public class DeleteEquipmentCommandHandler : IRequestHandler<DeleteEquipmentCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<EquipmentTable> equipRep;

        public DeleteEquipmentCommandHandler(IBaseRepository<EquipmentTable> equipRep)
        {
            this.equipRep = equipRep;
        }

        public async Task<ApiResult<int>> Handle(DeleteEquipmentCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.查询失败;
            result.Message=ResultCode.查询失败.ToString();
            var res=equipRep.GetAll().FirstOrDefault(x=>x.EquipmentId==request.EquipmentId);
            res.IsDelete=true;
            await equipRep.UpdAsync(res);
            return await Task.FromResult(result);

        }
    }
}
